!
!
! Roel Matthysen
! s0202264
! 
!
!
! Tijdsbesteding zoals vermeld in verslag: ongeveer 4 uur.
! Bij dit programma zijn sommige dingen overgenomen uit het programma SampleFM.
!

      PROGRAM TEST

      USE FMZM

      IMPLICIT NONE

!             Multiprecisievariabelen declareren

      TYPE (FM), SAVE :: X1, X3, X4, EXACT

!             Gewone variabelen

      CHARACTER(80)  :: ST1
      CHARACTER(175) :: FMT
      INTEGER :: ITER, NDIGITS

!             Precisie instellen

      CALL FM_SET(10000)

!             Startwaarde, exacte oplossing

      X1 = TO_FM('0.9789')
      call FM_PI(EXACT)
      EXACT = exp(log(exact/2)/13)
      NDIGITS = int(floor(-log10(abs((X1-EXACT)/EXACT))))

!            Eerste iteratie printen

      FMT = "(//' Sample 1.  Real root of f(x) = cos(x**13)'//"// &
            "' Iteration       Newton approximation relative error                           correct digits')"
      WRITE (*   ,FMT)

      CALL FM_FORM('E65.55',(X1-EXACT)/EXACT,ST1)
      WRITE (*   ,"(/I10,4X,A, 4X,I4)") 0,TRIM(ST1),NDIGITS

      DO ITER = 1, 16

!                 X3 is f(X1).

         X3 = cos(X1**13)

!                 X4 is f'(X1).

         X4 = -13*X1**12*sin(X1**13)

!                 X1 updaten

         X1 = X1 - X3/X4
         NDIGITS = int(floor(-log10(abs((X1-EXACT)/EXACT))))
!                 Resultaten van de iteratie printen

         CALL FM_FORM('E65.55',(X1-exact)/exact,ST1)
         WRITE (*   ,"(/I10,4X,A,4X,I4)") ITER,TRIM(ST1), NDIGITS

      ENDDO


      END PROGRAM TEST

